<?php
/**
 * 作者：亿泽
 * QQ：1260435972
 * 交流群：557649112
 * 日期：2022/03/31
 * 项目名称：亿泽不用验证系统
 * 项目说明：请勿进行违法用途，当您在使用本项目中的任何源代码时默认同意作者的观点！
 * 观点：
 * 1.禁止将本系统使用于违法违规用途。
 * 2.禁止将本系统使用包含但不限于 灰色产业/进行灰色产业的机器人插件/框架。
 * 3.禁止进行商业性质的二创二开，仅授权免费个人使用
 * 4.本系统为免费/全开源项目，禁止进行任何商业活动 除非 获得作者授权！
 * 感谢：
 * 1.使用了 光年 后台模板
 * 2.参考了 网络上部分代码资料
 * 3.感谢各位的使用~
 **/
require_once "../include/common.php";
require_once "header.php";
$title = '版本增加 - 亿泽不用验证后台管理系统';
if ($islogin == 1) {
} else exit("<script>window.location.href='./login.html';</script>");
?>
<link href="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet">
<?php
if ($_GET['my'] == 'upstate') {

    $id = intval ($_GET['id']);
    $appid = intval ($_GET['appid']);
    $row = Db ::table ("appver") -> find ("*" , "id='$id' AND bd_appid = '$appid'") -> fetch ();
    if ($row == '') exit(popup ("不存在该ID，请检查或添加应用！" , 3));
    if (isset($_POST['submit'])) {
        $appver = daddslashes ($_POST['appver']);
        $title = daddslashes ($_POST['title']);
        $subtitle = daddslashes ($_POST['subtitle']);
        $vername = daddslashes ($_POST['vername']);
        $free = daddslashes ($_POST['free']);
        $update = daddslashes ($_POST['update']);
        $log = daddslashes ($_POST['log']);
        $download = daddslashes ($_POST['download']);
        $affiche = daddslashes ($_POST['affiche']);
        $expire = daddslashes (strtotime ($_POST['expire']));
        $auth = daddslashes ($_POST['auth']);
        $enable = daddslashes ($_POST['enable']);

        $sql = "UPDATE `yz_appver` SET `bd_appid`='$appid', `version`='$appver', `title`='$title', `subtitle`='$subtitle', `vername`='$vername', `free`='$free', `update`='$update', `log`='$log', `download`='$download', `affiche`='$affiche', `expire`='$expire', `auth`='$auth', `enable`='$enable' WHERE `id`= '$id';";
        if (Db ::table ("appver") -> rawexec ($sql) != 0) {
            popup ("修改成功！" , 2 , "0" , "ver_list.php");
        } else popup ("修改失败！" , 3);
    } else {
        ?>
        <div class="container-fluid p-t-15">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <header class="card-header">
                            <div class="card-title"><a href="var_list.php" data-toggle="tooltip"
                                                       data-original-title="返回版本列表"
                                                       class="mdi mdi-reply-all"> &nbsp;</a>&nbsp;编辑应用版本
                            </div>
                        </header>
                        <div class="card-body">
                            <form action="./ver_edit.php?my=upstate&id=<?php echo $id; ?>&appid=<?php echo $appid; ?>"
                                  method="post">
                                <div class="form-row">
                                    <div class="input-group">
                                        <div class="col-md-6 mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">应用选择</span>
                                            </div>
                                            <select class="custom-select" name="appid" id="validationTooltip04"
                                            >
                                                <?php
                                                $re = Db ::table ("applist") -> find ("*");
                                                while ($rec = $re -> fetch ()) {
                                                    $s1 = $rec['name'];
                                                    $s2 = $rec['appid'];
                                                    $s3 = "";
                                                    if ($appid == $s2) {
                                                        $s3 = "selected";
                                                    };
                                                    echo '<option ' . $s3 . ' value="' . $s2 . '">名称：' . $s1 . ' | ID：' . $s2 . '</option>';
                                                }
                                                ?>
                                            </select>
                                            <div class="invalid-tooltip">
                                                请选择有效状态。
                                            </div>
                                        </div>
                                        <div class="col-md-6 mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">版本</span>
                                            </div>
                                            <select class="custom-select" name="vername" id="validationTooltip04"
                                                    required>
                                                <option value="0" <?php if ($row['vername'] == 0) echo ("selected"); ?>>
                                                    - 预览版 - Pre-alpha
                                                </option>
                                                <option value="1" <?php if ($row['vername'] == 1) echo ("selected"); ?>>
                                                    - 内测版 - Alpha
                                                </option>
                                                <option value="2" <?php if ($row['vername'] == 2) echo ("selected"); ?>>
                                                    - 公测版 - Beta
                                                </option>
                                                <option value="3" <?php if ($row['vername'] == 3) echo ("selected"); ?>>
                                                    - 最终测试版 - Gamma
                                                </option>
                                                <option value="4" <?php if ($row['vername'] == 4) echo ("selected"); ?>>
                                                    - 稳定版 - Stable
                                                </option>
                                                <option value="5" <?php if ($row['vername'] == 5) echo ("selected"); ?>>
                                                    - 发行版 - Release
                                                </option>
                                                <option value="6" <?php if ($row['vername'] == 6) echo ("selected"); ?>>
                                                    - 零售版 - Retail
                                                </option>
                                            </select>
                                            <div class="invalid-tooltip">
                                                请选择有效状态。
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text">版本号</span>
                                    </div>
                                    <input type="text" class="form-control" name="appver"
                                           value="<?php echo $row['version']; ?>"
                                           placeholder="请输入版本号，请注意格式！">
                                </div>

                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text">标题</span>
                                    </div>
                                    <input type="text" class="form-control" name="title"
                                           value="<?php echo $row['title']; ?>"
                                           placeholder="请输入标题">
                                </div>

                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text">副标题</span>
                                    </div>
                                    <input type="text" class="form-control" name="subtitle"
                                           value="<?php echo $row['subtitle']; ?>"
                                           placeholder="请输入副标题">
                                </div>
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text">收费模式</span>
                                    </div>
                                    <select class="custom-select" name="free" required>
                                        <option value="0" <?php if ($row['free'] == 0) echo ("selected"); ?>>免费</option>
                                        <option value="1" <?php if ($row['free'] == 1) echo ("selected"); ?>>收费</option>
                                    </select>
                                    <div class="invalid-tooltip">
                                        请选择收费模式。
                                    </div>
                                </div>
                                <div class="form-row">
                                    <div class="input-group">
                                        <div class="col-md-6 mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">更新日期</span>
                                            </div>
                                            <input class="form-control" type="text" data-provide="datetimepicker"
                                                   name="update"
                                                   placeholder="请选择具体时间" value="<?php echo $row['update']; ?>"
                                                   data-side-by-side="true"
                                                   data-format="YYYY-MM-DD HH:mm:ss"/>
                                        </div>
                                        <div class="col-md-6 mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text">结束时间</span>
                                            </div>
                                            <input class="form-control" type="text" data-provide="datetimepicker"
                                                   name="expire"
                                                   placeholder="请选择具体时间"
                                                   value="<?php echo date ('Y-m-d H:i:s' , $row['expire']); ?>"
                                                   data-side-by-side="true"
                                                   data-format="YYYY-MM-DD HH:mm:ss"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="input-group-prepend mb-3">
                                    <span class="input-group-text">公告说明</span>
                                    <textarea class="form-control" name="affiche"
                                              aria-label="With textarea"><?php echo $row['affiche']; ?></textarea>
                                </div>

                                <div class="input-group-prepend mb-3">
                                    <span class="input-group-text">更新日志</span>
                                    <textarea class="form-control" name="log"
                                              aria-label="With textarea"><?php echo $row['log']; ?></textarea>
                                </div>

                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text">下载链接</span>
                                    </div>
                                    <input type="text" class="form-control" name="download"
                                           value="<?php echo $row['download']; ?>"
                                           placeholder="请输入该版本的下载链接！">
                                </div>

                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text">验证模式</span>
                                    </div>
                                    <select class="custom-select" name="auth" required>
                                        <option value="0" <?php if ($row['auth'] == 0) echo ("selected"); ?>>无需验证
                                        </option>
                                        <option value="1" <?php if ($row['auth'] == 1) echo ("selected"); ?>>账号密码验证
                                        </option>
                                        <option value="2" <?php if ($row['auth'] == 2) echo ("selected"); ?>>卡密授权验证
                                        </option>
                                    </select>
                                    <div class="invalid-tooltip">
                                        请选择验证模式。
                                    </div>
                                </div>

                                <div class="input-group mb-3">
                            <span class="input-group-text"><input type="radio" id="status1" name="enable" value="1"
                                                                  <?php if ($row['enable'] == 1) echo ("checked"); ?>>&nbsp;正常</span>
                                    <span class="input-group-text"><input type="radio" id="status2" name="enable"
                                                                          value="2" <?php if ($row['enable'] == 2) echo ("checked"); ?>>&nbsp;维护</span>
                                    <span class="input-group-text"><input type="radio" id="status3" name="enable"
                                                                          value="0" <?php if ($row['enable'] == 0) echo ("checked"); ?>>&nbsp;禁用</span>
                                </div>
                                <div class="input-group">
                                    <input class="btn btn-block btn-label btn-primary" type="submit" name="submit"
                                           value="修改">
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

            </div>

        </div>
        <?php
    }
} elseif ($_GET['my'] == 'del') {
    $idd = intval ($_GET['id']);
    $appid = intval ($_GET['appid']);
    $sql = "DELETE FROM yz_appver WHERE id='$id' AND appid='$appid' limit 1";
    if (Db ::table ("appver") -> rawexec ($sql) != 0) {
        popup ("指令：删除 --> 操作成功！" , 2);
    } else popup ("指令：删除 --> 操作失败！" , 2);;
}
?>
<!--时间日期选择器-->
<script type="text/javascript" src="js/moment.js/moment.min.js"></script>
<script type="text/javascript" src="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="js/moment.js/locale/zh-cn.min.js"></script>
